package com.thwcompany.controller;
import com.thwcompany.service.DelaySendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
/**
 * @program: springboot-rabbit-mq
 * @author: tenghw
 * @create: 2024-01-27 14:56
 * @Version 1.0
 * @description: 发送延迟消息：
 **/
@Controller
@Slf4j
@SuppressWarnings("all")
public class DelayedQueueController {
    public static final String DELAYED_EXCHANGE_NAME = "delayed.exchange";// 延迟交换机名称
    public static final String DELAYED_ROUTING_KEY = "delayed.routingKey";// 延迟队列绑定的路由键

    @Autowired
    DelaySendService delayedSendService;

    // 开始发消息（基于插件的）：消息+延迟时间
    @GetMapping("/sendDelayMessage")
    @ResponseBody
    public void sendDelayMessage(@RequestParam("message") String message, @RequestParam("delayTime") Integer delayTime) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        log.info("生产者发送延迟消息，当前时间：{}，发送一条延迟时间为：{}毫秒的消息，给延迟队列delayed.queue，该消息为：{}",LocalDateTime.now().format(formatter) , delayTime , message);
        delayedSendService.sendDelayMessage( message, delayTime);
    }
}